<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>我的成绩系统</title>

  <!-- icheck bootstrap -->
  <link rel="stylesheet" href="/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/dist/css/adminlte.min.css">
</head>
<body class="hold-transition login-page">
<div class="login-box">
  <!-- /.login-logo -->
  <div class="card card-outline card-primary">
    <div class="card-header text-center">
      <a href="/index2.html" class="h1"><b>我的成绩管理系统</b></a>
    </div>
    <div class="card-body">
      <p class="login-box-msg">看成绩，紧张吗？</p>

      <form action="#" method="post">
        <div class="input-group mb-3">
          <input type="text" class="form-control" placeholder="学号" id="txtName" name="txtName">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-envelope"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="password" class="form-control" placeholder="密码" id="txtPassword" name="txtPassword">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-lock"></span>
            </div>
          </div>
        </div>
          <!-- /.col -->
          <div class="col-4">
            <a href="#" class="btn btn-primary btn-block " onclick="login()">登录</a>
          </div>
      </form>

<!--      &lt;!&ndash; /.social-auth-links &ndash;&gt;-->

<!--      <p class="mb-1">-->
<!--        <a href="forgot-password.html">I forgot my password</a>-->
<!--      </p>-->
<!--      <p class="mb-0">-->
<!--        <a href="register.html" class="text-center">Register a new membership</a>-->
<!--      </p>-->
    </div>
    <!-- /.card-body -->
  </div>
  <!-- /.card -->
</div>
<!-- /.login-box -->

<!-- jQuery -->
<script src="/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="/dist/js/adminlte.min.js"></script>

<script>
  function login() {

    // if(!$("#frmLogin").valid()){
    //
    //   return false;
    // }
    //1) 取用户名和密码

    var name = $("#txtName").val();
    var password = $("#txtPassword").val();


    //2) ajax 提交

    $.ajax({
      method: "POST",
      url: "/api/login/student",
      data: {
        "name":name,
        "password":password
      }
    })
            .done(function (result) {

              var code=result.code;
              var msg=result.msg;
              if (code!=null && code >= 0) {
                //3)  如果成功，则转入到主页面
                window.location.href="/student/list"

              } else {
                alert("出错了！"+msg);
              }

            });


  }

</script>
</body>
</html>
